package com.acme.task1;

public class Calculator {
    public final static String ERR_NUM_ARGS = "Calculator accepts only 3 arguments: 'x1 (+, -, x, /) x2' ";
    public final static String ERR_MUST_BE_NUM = "First and last arguments must be numbers(double)";
    public final static String ERR_UNSUPP_OP = "Unsupported operator. Must be '+, -, x, /'";

    public static void main(String[] args) {
        if (args.length < 3) {
            System.out.println(ERR_NUM_ARGS);
            return;
        }


        double operand1;
        double operand2;
        try {
            operand1 = Double.parseDouble(args[0]);
            operand2 = Double.parseDouble(args[2]);
        } catch (NumberFormatException e) {
            System.out.println(ERR_MUST_BE_NUM);
            return;
        }

        double result;
        char operator = args[1].charAt(0);
        switch (operator) {
            case '+':
                result = operand1 + operand2;
                break;
            case '-':
                result = operand1 - operand2;
                break;
            case 'x':
                result = operand1 * operand2;
                break;
            case '/':
                result = operand1 / operand2;
                break;
            default:
                System.out.println(ERR_UNSUPP_OP);
                return;

        }

        System.out.println(result);


    }
}
